package sparkCore

import org.apache.spark.{SparkConf, SparkContext}

object FileRdd2 {

  def main(args: Array[String]): Unit = {

    //1.构建spark 的配置项
    val conf = new SparkConf().setMaster("local[*]").setAppName("FileRdd2")
    //2.构建sparkcontext sc
    val sc = new SparkContext(conf)

    val obj1 = sc.textFile("D:\\IdeaCodes\\code\\log\\teacher.log")
    val teachers = obj1.map(url => url.split("/").last).map(teacher => (teacher,1))
    val rteachers = teachers.reduceByKey(_+_)

    val mostPopularTeacher = rteachers.reduce((a,b)=> if (a._2 > b._2) a else b)
    println(mostPopularTeacher)

    sc.stop()







  }

}
